package com.lzy.thread;

import java.util.concurrent.locks.ReentrantLock;

/**
 * Author: lzy
 * Date:   2020/06/16 11:30
 * Description:
 **/
public class TLTest {

    public static Object A_LOCK = new Object();
    public static Object B_LOCK = new Object();

    public static void main(String[] args) throws InterruptedException {
//        ThreadA a = new ThreadA();
//        ThreadB b = new ThreadB();
//        a.start();
//        b.start();
        for(;;){
            TLTest lzy = new TLTest();
            Thread.sleep(10);
        }
    }

}


class ThreadA extends Thread{

    @Override
    public void run() {
        synchronized (TLTest.A_LOCK){
            System.out.println("A线程获取到了A_LOCK");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (TLTest.B_LOCK){
                System.out.println("A线程获取到了B_LOCK");
            }
        }
    }
}


class ThreadB extends Thread{

    @Override
    public void run() {
        synchronized (TLTest.B_LOCK){
            System.out.println("B线程获取到了B_LOCK");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (TLTest.A_LOCK){
                System.out.println("B线程获取到了A_LOCK");
            }
        }
    }
}